﻿using System;
using System.IO;
using System.Diagnostics;

namespace FakePoint
{
  public class Test
  {
    public static bool Verify(string value)
    { // create an empty "expected" file if it doesn't already exist
      string path = System.Reflection.Assembly.GetCallingAssembly().CodeBase.Replace("file:///", "");
      if (path.Contains("TestResults")) path = path.Substring(0, path.IndexOf("TestResults"));
      path = Path.GetDirectoryName(path).Replace("\\bin\\Debug", "");
      var method = new StackTrace().GetFrame(1).GetMethod();
      string fileName = path + "\\" + method.DeclaringType.Name + "." + method.Name;
      var fs = new FileStream(fileName + ".expected", FileMode.OpenOrCreate);
      var sr = new StreamReader(fs);
      string contents = sr.ReadToEnd();
      sr.Close();
      fs.Close();
      if (value != contents)
      {
        var sw = new StreamWriter(fileName + ".actual");
        sw.Write(value);
        sw.Close();
        return false;
      }
      else
      {
        File.Delete(fileName + ".actual");
        return true;
      }
    }
  }
}
